﻿namespace Wicresoft.Busi.BizLogic
{
    using System.Data;
    using Wicresoft.Busi.Entity;

    public class BLDepartment : BasePage
    {
        public static DataTable GetAllDept()
        {
            DataTable dt = Organization.GetSingleGroup(Util.RootGroupID).GetChildMember();
            DataTable dtResult = new DataTable("Dept");
            dtResult.Columns.Add("NodeID", typeof(long));
            dtResult.Columns.Add("NodeDisplayName", typeof(string));
            dtResult.Columns.Add("RelationOrder", typeof(long));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["NodeTypeCode"].ToString() == NodeCodeType.GROUP)
                {
                    if (Util.Deep == 2)
                    {
                        DataRow dr = dtResult.NewRow();
                        dr["NodeID"] = long.Parse(dt.Rows[i]["NodeID"].ToString());
                        dr["NodeDisplayName"] = dt.Rows[i]["NodeDisplayName"].ToString();
                        dr["RelationOrder"] = i * 0x2710;
                        dtResult.Rows.Add(dr);
                    }
                    else
                    {
                        DataTable dt1 = Organization.GetSingleGroup(long.Parse(dt.Rows[i]["NodeID"].ToString())).GetChildMember();
                        for (int j = 0; j < dt1.Rows.Count; j++)
                        {
                            if (dt1.Rows[j]["NodeTypeCode"].ToString() == NodeCodeType.GROUP)
                            {
                                DataRow dr = dtResult.NewRow();
                                dr["NodeID"] = long.Parse(dt1.Rows[j]["NodeID"].ToString());
                                dr["NodeDisplayName"] = dt1.Rows[j]["NodeDisplayName"].ToString();
                                dr["RelationOrder"] = (i * 0x2710) + j;
                                dtResult.Rows.Add(dr);
                            }
                        }
                    }
                }
            }
            return dtResult;
        }

        public static DataTable GetLeadGroups()
        {
            DataTable dtResult = new DataTable("Dept");
            dtResult.Columns.Add("NodeID", typeof(long));
            dtResult.Columns.Add("NodeDisplayName", typeof(string));
            dtResult.Columns.Add("RelationOrder", typeof(long));
            foreach (long leadGroupId in Util.LeaderGroupIDs)
            {
                DataTable dt1 = Organization.GetSingleGroup(leadGroupId).GetChildGroup(true);
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    if (dt1.Rows[j]["NodeTypeCode"].ToString() == NodeCodeType.GROUP)
                    {
                        DataRow dr = dtResult.NewRow();
                        dr["NodeID"] = long.Parse(dt1.Rows[j]["NodeID"].ToString());
                        dr["NodeDisplayName"] = dt1.Rows[j]["NodeDisplayName"].ToString();
                        dr["RelationOrder"] = 0x2710 + j;
                        dtResult.Rows.Add(dr);
                    }
                }
            }
            return dtResult;
        }
    }
}

